#pragma once

#include "InteractionOperand.h"

#include "InteractionConstraint.h"
#include "InteractionFragment.h"

namespace uml {

InteractionOperand::InteractionOperand(const QString& umlType)
    : NamedElement(umlType) {}

void InteractionOperand::fromJson(const QJsonObject& json, QStringList& errorList) {
    if (json.isEmpty()) {
        return;
    }

    NamedElement::fromJson(json, errorList);
    InteractionFragment::fromJson(json, errorList);
    Namespace::fromJson(json, errorList);
    JsonSerializable::fromJsonArray(fragments_, "fragments", json, errorList);
    guard_ = JsonSerializable::create<InteractionConstraint>(json.value("guard"), errorList);

}

void InteractionOperand::toJson(QJsonObject& json) {
    NamedElement::toJson(json);
    InteractionFragment::toJson(json);
    Namespace::toJson(json);
    JsonSerializable::toJsonArray(fragments_, "fragments", json);
    if (guard_) {
        QJsonObject guard_json;
        guard_->toJson(guard_json);
        json.insert("guard", guard_json);
    }
}

/// <summary>
/// fragments getter
/// The fragments of the operand.
/// </summary>
vector<shared_ptr<InteractionFragment>>& InteractionOperand::fragments() {
    return fragments_;
}

/// <summary>
/// guard getter
/// Constraint of the operand.
/// </summary>
shared_ptr<InteractionConstraint> InteractionOperand::guard() const {
    return guard_;
}

/// <summary>
/// guard setter
/// Constraint of the operand.
/// </summary>
void InteractionOperand::setGuard(shared_ptr<InteractionConstraint> value) {
    guard_ = value;
}

} // namespace uml
